var tpl = _include('./index.html');
var Data = require('/src/modules/data.js');

var scenes = {
    template: tpl,
    props:['code'],
    data:function(){
        return {
            scenes:[]
        }
    },
    computed:{
        scenescode:{
            get:function(){
                return this.code;
            },
            set:function(){

            }
        }
    },
    beforeCreate:function(){
        Data.getScene(function(res){
            this.$data.scenes = res.data;
        }.bind(this))
    },
    updated:function(){
        $("#J_scene").select2();

    },
    mounted:function(){
        $("#J_scene").on('select2:select',function(e){
            var id = e.params.data.id;
            if(this.scenescode.indexOf(id)===-1){
                this.scenescode.push(id);
            }
        }.bind(this));
        $("#J_scene").on('select2:unselect',function(e){
            var id = e.params.data.id;
            var index = this.scenescode.indexOf(id);
            this.scenescode.splice(index,1);
        }.bind(this));
    }
};

module.exports = scenes;